import { useState } from 'react';
import useLoading from './loding';

export function useBaseModel<T, A extends any[]>(
  getData: (...args: A) => Promise<T>
){

  const [data, setData] = useState<T>()

  const loadData = useLoading(async (...args: A) => {
    const result = await getData(...args)
    setData(result)
  }, [])
  
  return {
    data,
    loadData,
    setData,
  }
}